package com.atguigu.java;

/**
 * @author shkstart
 * @create 2022-08-05-13:41
 */
public class ArrayLearn {

    public static void main(String[] args) {
        int[] arr ={1,2,3,5,7,9};
        for(int i : arr){
            System.out.println(i);
        }
        int[] arr1 =arr;
        arr1[0]=100;
        System.out.println(arr[0]);

        /**
         *
         * 每走一次循环，就将数组的元素依次赋值给临时变量，但无法发改变数组
         * for(临时变量 ： 数字名称）{
         *
         * }
         */
    }
    public static int binSearch(int[] arr,int toFind){
        int left = 0;
        int right = arr.length-1;


        while(left<=right){
            int mid = (left+right)/2;
            if(arr[mid]==toFind){
                System.out.println("找到了");
                return mid;
            }else if(arr[mid]<toFind){
                //向右边查找
                left = mid+1;
            }else{
                //向左查找
                right= mid-1;
            }
        }
        return -1;
    }

}
